package com.mg.pluginwebservice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mg.pluginwebservice.entity.ProductData;
import com.mg.pluginwebservice.util.HttpRequestUtils;

import java.io.IOException;
import java.util.List;

public class TestMain {

    public static void main(String[] args) {
        String m_strVipHost = "http://183.230.183.18:8088/SPPMDataService/services/data/query";
        JSONObject param = new JSONObject();
        param.put("param", "{\"Function\":\"monitor.getvips\",\"CustomParams\":{areacode:\"50\"},\"Type\":2}");
        JSONArray vipJsonData = executeMethod(m_strVipHost, param, HttpRequestUtils.CONTENT_TYPE_X_FORM).getJSONArray("data");
        List<ProductData> vipData = JSON.parseArray(vipJsonData.toJSONString(), ProductData.class);
        System.out.println(vipJsonData.toJSONString());
    }

    private static JSONObject executeMethod(String wsdlUrl, JSONObject param, String contentType) {
        JSONObject data = null;
        try {
            data = HttpRequestUtils.httpPost(wsdlUrl, param, contentType);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }
}
